package 华为OD机试真题2023.进阶题;

import utils.MyUtil;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class HJ14_最优资源分配 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/进阶题/input/14.txt"));
        MyUtil.START();
        Solution(in);
//        Solution2(in);
        MyUtil.END();
    }

    static void Solution(Scanner in) {
        int M = in.nextInt();
        int N = in.nextInt();
        Map<Character, Integer> need = new HashMap<Character, Integer>() {{
            put('A', 1);
            put('B', 2);
            put('C', 8);
        }};
        in.nextLine(); //吸收回车
        char[] cArray = in.nextLine().toCharArray();
        int[] res = new int[N];
        for (int i = 0; i < N; i++) {
            res[i] = M;
        }
        for (char a : cArray) {
            int num = need.get(a);
            for (int i = 0; i < N; i++) {
                if (res[i] >= num) {
                    res[i] -= num;
                    break;
                }
            }
        }
        for (int i = 0; i < N; i++) {
            StringBuffer result = new StringBuffer();
            for (int j = 0; j < M - res[i]; j++) {
                result.append(1);
            }
            for (int j = 0; j < res[i]; j++) {
                result.append(0);
            }
            System.out.println(result);
        }
    }

    static void Solution2(Scanner sc) {
        int M = sc.nextInt();
        int N = sc.nextInt();
        sc.nextLine();
        String string = sc.nextLine();

        int[] chip = new int[N];    //板卡上的芯片
        int conf; //配置所占容量
        for (int i = 0; i < string.length(); i++) {
            char c = string.charAt(i);
            if (c == 'A') {
                conf = 1;
            } else if (c == 'B') {
                conf = 2;
            } else {
                conf = 8;
            }
            for (int j = 0; j < N; j++) {
                int used = chip[j];     //芯片占用的情况
                if (M - used >= conf) {  //芯片所剩容量大于等于配置所占容量
                    chip[j] += conf;
                    break;
                }
            }
        }

        for (int i = 0; i < N; i++) {
            StringBuffer sb = new StringBuffer();
            int used = chip[i];     //芯片占用的情况
            for (int j = 0; j < M; j++) {
                if (j < used) {     //芯片占用的地方为1，未占用为0
                    sb.append("1");
                } else {
                    sb.append("0");
                }
            }
            System.out.println(sb);
        }
    }
}
